package com.zjkj.mp.dao.notice.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zjkj.mp.dao.DaoBase;
import com.zjkj.mp.dao.notice.NoticeDAO;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.notice.Notice;

@Repository
public class NoticeDAOImpl extends DaoBase implements NoticeDAO{

	@Override
	public void addNotice(Notice notice) {
		 getSqlMapClient().insert("insert.addNotice",notice);
	}

	@Override
	public PaginatedResult getList(int pageNo, int pageSize,	Map<String, Object> params) {
		 PaginatedResult result = new PaginatedResult(pageNo, pageSize);
		 List list = getSqlMapClient().queryForList("get.listNotice", params, (pageNo-1)*pageSize,pageSize);
		 result.setResult(list);
		 
		 int totalCount = ((Integer)getSqlMapClient().queryForObject("get.listNoticeCount",params)).intValue();
		 result.setTotalSize(totalCount);
		 
		 return result;
	}

	@Override
	public void updateNotice(Notice notice) {
		 getSqlMapClient().update("update.Notice",notice);
	}

	@Override
	public void deleteNotice(int id) {
	  getSqlMapClient().delete("delete.notice",new Integer(id));
	}

	@Override
	public Notice getById(int id) {
		return (Notice) getSqlMapClient().queryForObject("get.getNoticeById",new Integer(id));
	} 
}